﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.VisualBasic;
using System.Xml.Linq;
using WebApplication1.Utils;

namespace WebApplication1.Controllers
{

    [ApiController]
    [Route("[controller]/[action]")]
    public class HomeController : Controller
    {
        private readonly RedisService _redisService;

        public HomeController(RedisService redisService)
        {
            _redisService = redisService;
        }

        [HttpPost(Name = "Add")]
        public String Add(String ID)
        {
            //Console.WriteLine(value);

            //判断如果redis中不存在将要插入的键
            if (!_redisService.isExists("USERID_" + ID))
            {
                String guid = Guid.NewGuid().ToString();
                //插入redis键值对
                _redisService.SetValue("USERID_" + ID, guid);
                
                //更新表数据
                string str = "update TEST1 t set t.SAL = t.SAL + 10 where t.ID = " + ID;
                ConnectOracle.connect(str);

                //为了演示方便，将线程睡眠15秒钟
                Thread.Sleep(15000);

                //删除redis键值
                bool isDel = _redisService.DelValue("USERID_" + ID);
                return (isDel == true ? "更新完成" : "更新失败");
            }
            else
            {
                return "更新中。。。";
            }



        }
    }




}
